package com.antd.gateway;

import com.antd.gateway.limit.RemoteAddrKeyResolver;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.SpringCloudApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.context.annotation.Bean;
import org.springframework.web.filter.reactive.HiddenHttpMethodFilter;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilterChain;
import reactor.core.publisher.Mono;

/**
 * TODO
 *
 * @author 子丶沫
 * @version 1.0
 * @date 2020/11/19 15:00
 */
@SpringCloudApplication
@EnableDiscoveryClient
@EnableHystrix
public class AntdGatewayApplication {
    public static void main(String[] args) {
        SpringApplication.run(AntdGatewayApplication.class,args);
    }

    @Bean(name = RemoteAddrKeyResolver.BEAN_NAME)
    public KeyResolver keyResolver(){
        return new RemoteAddrKeyResolver();
    }
    @Bean
    public HiddenHttpMethodFilter httpMethodFilter(){
        return new HiddenHttpMethodFilter(){
            @Override
            public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
                return chain.filter(exchange);
            }
        };
    }
}
